//package com.lebang.schedule;
//
//import com.alibaba.fastjson.JSON;
//import com.lebang.common.validcode.ValidCodeUtil;
//import com.lebang.component.RedisClient;
//import com.lebang.domain.ClickStrategyDetail;
//import com.lebang.domain.TaskRouseClick;
//import com.lebang.mapper.LbbMemberMapper;
//import com.lebang.model.DownSendModel;
//import com.lebang.model.Whether;
//import com.lebang.model.enums.buss.RewardTypeUscan;
//import com.lebang.service.ClickStrategyDetailService;
//import com.lebang.service.DownAppService;
//import com.lebang.service.MemberNoticeService;
//import com.lebang.service.TaskRouseClickService;
//import com.lebangweb.common.UUIDUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.math.BigDecimal;
//import java.time.LocalDate;
//import java.time.format.DateTimeFormatter;
//import java.util.Map;
//
///**
// * @Author: hwq
// * @Date: 2019/10/9 15:46
// * @Version 1.0
// */
//@Slf4j
//@Component
//public class DownTask {
//    @Autowired
//    private DownAppService downAppService;
//    @Autowired
//    private RedisClient redisClient;
//    @Autowired
//    private ValidCodeUtil validCodeUtil;
//    @Autowired
//    private TaskRouseClickService taskRouseClickService;
//    @Autowired
//    private LbbMemberMapper lbbMemberMapper;
//    @Value("${info.is-cences}")
//    private Boolean isStar;
//    @Autowired
//    private ClickStrategyDetailService clickStrategyDetailService;
//    @Autowired
//    private MemberNoticeService memberNoticeService;
//    /**
//     * 每日9点检查通知签到。
//     */
//    @Scheduled(cron = "0 0 9 * * ?")
//    public void execute() {
//        if(!isStar){
//            return;
//        }
//        if(!redisClient.tryGetDistributedLock("lock:Scheduled:DownTask:execute", UUIDUtil.M(),100000)) {
//            return;
//        }
//        LocalDate now = LocalDate.now();
//        String str = now.format(DateTimeFormatter.ISO_DATE);
//        Map<String, String> today = redisClient.hgetall(downAppService.getClickSendKey()+str);
//        today.forEach((rouses, TaskRouseClickId) -> {
//            try {
//                DownSendModel vo = JSON.parseObject(rouses, DownSendModel.class);
//                if (vo != null) {
//                    //检查是否已签到
//                    if (!downAppService.checkClickByMemberId(vo.getMemberId(), vo.getRouseId(), now)) {
//                        if(vo.isMy()){
//                            ClickStrategyDetail click = clickStrategyDetailService.selectById(Long.valueOf(TaskRouseClickId));
//                            if (click != null) {
//                                if (click.getHasSendMsg().equals(Whether.YES.getDbIndex()) && click.getEnable().equals(Whether.YES.getDbIndex())) {
//                                    String phone = lbbMemberMapper.selectPhoneByMemberId(vo.getMemberId());
//                                    if (phone != null) {
//                                        String money="";
//                                        if(click.getRewardType().equals(RewardTypeUscan.Point.getIndex())){
//                                            money=click.getDayPoint()+"金币";
//                                        }else {
//                                            money=new BigDecimal(click.getDayMoney()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN) +"元";
//                                        }
//                                        //validCodeUtil.sendMsgByCl(phone, vo.getAppName(),money);
//                                       // memberNoticeService.addNoticeAndPush("签到通知",vo.getAppName());
//                                    }
//                                }
//                            }
//                        }else {
//                            TaskRouseClick click = taskRouseClickService.selectById(Long.valueOf(TaskRouseClickId));
//                            if (click != null) {
//                                if (click.getHasSendMsg().equals(Whether.YES.getDbIndex()) && click.getEnable().equals(Whether.YES.getDbIndex())) {
//                                    String phone = lbbMemberMapper.selectPhoneByMemberId(vo.getMemberId());
//                                    if (phone != null) {
//                                        String money="";
//                                        if(click.getRewardType().equals(RewardTypeUscan.Point.getIndex())){
//                                            money=click.getDayPoint()+"金币";
//                                        }else {
//                                            money=new BigDecimal(click.getDayMoney()).divide(new BigDecimal(100),2,BigDecimal.ROUND_DOWN) +"元";
//                                        }
//                                        validCodeUtil.sendMsgByCl(phone, vo.getAppName(),money);
//                                    }
//                                }
//                            }
//                        }
//
//                    }
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        });
//        redisClient.del(downAppService.getClickSendKey()+str);
//        log.info("统计完成...");
//    }
//}
